package com.android.base.ui.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import me.yokeyword.fragmentation.SupportFragment;

/**
 * FileName: BaseFragment
 * Author: admin
 * Date: 2020/7/3 10:10
 * Description:
 */
public abstract class VBBaseFragment extends SupportFragment {

    public Activity activity;
    public ViewBinding viewBinding;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = getActivity();
    }

    /**
     * Activity跳转
     *
     * @param startAct
     * @param endAct
     * @return
     */
    public void startAct(Activity startAct, Activity endAct) {
        Intent intent = new Intent(startAct, endAct.getClass());
        startActivity(intent);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        viewBinding = getViewBinding(inflater);
        return viewBinding.getRoot();
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initView();
        initData();
        initLister();
    }

    public int BG_WHITE = 0;
    public int BG_BLACK = 1;

    //设置状态栏字体颜色
    public void setTitleBackground(int titleBackground) {
        if (titleBackground == 1) {//深色
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
        }

        if (titleBackground == 0) {//浅色
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            }
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (viewBinding != null) {
            viewBinding = null;
        }
    }

    protected abstract ViewBinding getViewBinding(LayoutInflater inflater);

    public void initData() {
    }

    public void initView() {
    }

    public void initLister(){

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}